/**
 *   Copyright 2014 Royce Remulla
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package cjcast.y2015.problem;

/**
 * 
 * @author royce.com@gmail.com
 */
public class LEDState {


    /** */
    private final transient byte byteValue;

    /** All flags on, excess (8th) left most flag set to OFF. */
    public static final byte LED_ALL_ON = 0x7F;


    /**
     * @param ledState LED on flags as '1', off as '0'. Must be a maximum of 7
     *            binary digits or else will throw NumberFormatException.
     */
    public LEDState(final String ledState) {
        this(Byte.parseByte(ledState, 2));
    }

    /**
     * @param ledState LED on flags as '1', off as '0'.
     */
    public LEDState(final byte ledState) {
        assert ledState <= LED_ALL_ON && ledState >= 0;

        byteValue = ledState;
    }

    public byte getByteValue()
    {
        return byteValue;
    }

    /** {@inheritDoc} */
    @Override
    public String toString()
    {
        return String.format(
            "%7s",
            Integer.toBinaryString(byteValue & LED_ALL_ON)).replace(' ', '0');
    }

}
